package io.renren.modules.avanotes.component;


import io.renren.common.to.mail.MailTo;
import io.renren.common.utils.MailUtil;
import org.apache.commons.mail.EmailException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * @author: xiaomi
 * @date: 2022/2/22
 * @description:
 */
@Component
public class MailComponent {

//    String host = "smtp.qq.com";
//    int port = 465;
//    String sender = "529742454@qq.com";
//    String name = "ZZR";
//    String username = "529742454@qq.com";
//    String password = "usuertrxocpsbjba";

    @Value("${mail.host}")
    private String host;
    @Value("${mail.port}")
    private Integer port;
    @Value("${mail.sender}")
    private String sender;
    @Value("${mail.name}")
    private String name;
    @Value("${mail.username}")
    private String username;
    @Value("${mail.password}")
    private String password;

    /**
     * 发送邮件
     *
     * @param recs 接收者
     * @param html 邮件信息
     */
    public boolean send(Set<String> recs, String title, String html) throws EmailException {
        MailTo r = new MailTo(host, port, sender, name, username, password, title, html, html, recs);
        return MailUtil.send(r);
    }
}
